﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using ConferenceRoomSchedule;
using System.Data;

namespace ConferenceRoomSchedule
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            //We need to get credentials...
          
            ExchangeProvider ep = new ExchangeProvider();

            string acct = Request.Params["Account"];
            string alias = Request.Params["Alias"];

            Response.Write(alias + "<p />");

            ep.UserName = "*****";
            ep.Password = "*****";
            ep.Domain = "*****";
            ep.ServiceURL = @"*****";
            
            IEnumerable<AppointmentData> lp = ep.RetrieveCalendars(acct);

             //var list = from a in lp
             //           where a.MeetingStartTime.Date.TimeOfDay <= DateTime.Today.TimeOfDay
             //               && a.MeetingEndTime.TimeOfDay >= DateTime.Today.TimeOfDay
             //          select a;

            var list = from a in lp
                       where a.MeetingStartTime <= DateTime.Now
                             && a.MeetingEndTime >= DateTime.Now
                       select a;

            if (list.Count() == 0)
            {
                Response.Write("Room is currently free");
            }
            else
            {
                Response.Write("Room is currently busy");
            }
                
            
            //Need to find out if this is a free slot...

             //List<AppointmentData> todaysAppt = ;

             DataTable table = CollectionHelper.ConvertTo<AppointmentData>(lp.ToList<AppointmentData>());

             DayPilotCalendar1.NameColumnName = "Subject";
             DayPilotCalendar1.BeginColumnName = "MeetingStartTime";
             DayPilotCalendar1.EndColumnName = "MeetingEndTime";
             DayPilotCalendar1.PkColumnName = "ID";

             DayPilotCalendar1.DataSource = table;
             DayPilotCalendar1.DataBind();

             string s = "test";
        }
    }
}
